home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!sun1!ua302aa
- From: ua302aa@sun1.lrz-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: Random numbers...?
- Date: 11 Jan 1996 13:43:25 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4d345t$i4t@sparcserver.lrz-muenchen.de>
- References: <30DDBEB1.4C42@aruba.ccit.arizona.edu> <DKDz1v.736@eskimo.com> <4d2c6o$h7l@maureen.teleport.com>
- NNTP-Posting-Host: sun1.lrz-muenchen.de
-
- muse@teleport.com (Andrew T Millard) writes:
-
- >: vaughn@aruba.ccit.arizona.edu says :
- >: >
- >: >Hello,
- >: >this, but I need to get some code that will simply generate a random
- >: >integer from 0 to 9. Specifically, I want to generate a string of
- >: >four random digits. I keep generating numbers that look suspiciously
- >: >non-random somehow (seeding the random number generator with the
-
- >Bill, this routine should do fine:
-
- >#include <stdio.h>
- >#include <math.h>
-
- There is no reason to include <math.h>, but there is a _good_ reason
- to include <stdlib.h>.
-
- >void main(void)
-
- I will not comment on this.
-
- >{
- > int iCount, digit[4];
- > srand(time()); /* Seeds random numbers */
- > for(iCount = 0; iCount <= 3; iCount++)
- > {
- > digit[iCount] = abs(rand() % 10);
-
- Have a look at the FAQ to find out why this _could be_ a poor RNG,
- depending on the implementation of rand().
-
- > }
- >}
-
- > If this doesn't work, then the Gods are just angry at you. :)
- > Newbie-man Bjornus
-
- If this does work, it is just luck.
-
- Kurt
-
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-